/*
 * @Author: yuanweijiang
 * @Date: 2025-02-11 15:26:27
 * @LastEditors: yuanweijiang
 */
import { Session } from '/@/utils/storage';

export default function (url, config) {
	let param = config.param;
	delete config.param;
	if (typeof param !== 'undefined') {
		let searchParams = new URLSearchParams();
		for (const key of Object.keys(param)) {
			searchParams.append(key, param[key]);
		}
		url = url + '?' + searchParams;
	}
	if (typeof config.body !== 'undefined') {
		config.body = JSON.stringify(config.body);
	}
	if (typeof config.headers === 'undefined') {
		config.headers = new Headers();
	}
	config.headers.append('Content-type', 'application/json');
	const token = Session.getToken();
	if (token != null) {
		config.headers.append('Authorization', `Bearer ${token}`);
	}
	return fetch(url, config).then((response) => {
		return response;
	});
}
